﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SnippetDoc.Entities;

namespace SnippetDoc.Utils
{
    public class CodeSampleInterpreter
    {
        private const string REPLACEMENT_SYMBOL = "$";
        private const string END_ANCHOR = "$end$";

        public string InterpreteSnippetTemplate(SnippetDetail snippetDetail)
        {
            if (snippetDetail == null)
                return null;

            string resolvedSnippetCode = snippetDetail.SnippetTemplate;

            if (snippetDetail.VariableDeclarations != null)
            {
                foreach (var variableDeclaration in snippetDetail.VariableDeclarations)
                {
                    resolvedSnippetCode = resolvedSnippetCode.Replace(REPLACEMENT_SYMBOL + variableDeclaration.Id + REPLACEMENT_SYMBOL, variableDeclaration.DefaultValue);
                }
            }

            return resolvedSnippetCode.Replace(END_ANCHOR, "");
        }
    }
}
